/* 
 * File:   Campaign.cpp
 * Author: agu
 * 
 * Created on 18 de junio de 2014, 17:11
 */

#include "editor_Campaign.h"
#include <iostream>

Campaign::Campaign() {
    this->numberLevels = 1;
    this->numberPlayers = 1;
    this->name = "";
    this->pathImage = "";
    this->difficult = "";
}

Campaign::Campaign(const Campaign& orig) {
}

Campaign::~Campaign() {
}

void Campaign::incrementPlayers() {
    this->numberPlayers++;
}

void Campaign::incrementLevels() {
    this->numberLevels++;
}

void Campaign::clear() {
    this->numberLevels = 1;
    this->numberPlayers = 1;
    this->name = "";
    this->pathImage = "";
    this->difficult = "";
}

void Campaign::setName(const string name) {
    this->name = name;
}

void Campaign::setPathImage(const string name) {
    this->pathImage = name;
}

void Campaign::save() {
    vectorS campaignInfo;
    campaignInfo.push_back(this->name);
    campaignInfo.push_back(this->pathImage);
    campaignInfo.push_back(this->difficult);
    campaignInfo.push_back(std::to_string(numberPlayers));
    this->parserXML.guardarDatos("campaigns/" + this->name + ".xml", campaignInfo, levelsInfo);

}
void Campaign::removeSave(){
    vectorS campaignInfo;
    campaignInfo.push_back(this->name);
    campaignInfo.push_back(this->pathImage);
    campaignInfo.push_back(this->difficult);
    campaignInfo.push_back(std::to_string(numberPlayers));
    std::remove(string("campaigns/" + this->name + ".xml").c_str());
    this->parserXML.guardarDatos("campaigns/" + this->name + ".xml", campaignInfo, levelsInfo);

}

void Campaign::setDifficult(const string difficult) {
    this->difficult = difficult;
}

void Campaign::setNumberPlayers(int number) {
    this->numberPlayers = number;
}

void Campaign::setNumberLevels(int number) {
    this->numberLevels = number;
}

bool Campaign::validate(string& msjError) {
    if (this->numberLevels < 1 || this->numberLevels > 10) {
        msjError="Numero de niveles invalido"; 
        return false;
    }

    if (this->numberPlayers < 1 || this->numberPlayers > 5){
        msjError="Numero de jugadores invalido"; 
        return false;
    }
        
    if (this->name.empty()){
        msjError="Debe elegir un nombre de campaña"; 
        return false;
    }
        
    if (this->pathImage.empty()){
        msjError="Debe elegir una imagen de campaña"; 
        return false;
    }
        
    if (this->difficult.empty()){
        msjError="Debe elegir una dificultad"; 
        return false;
    }
    msjError="";    
    return true;
}

unsigned int Campaign::getNumberLevels() {
    return this->numberLevels;
}

string Campaign::getDifficult() {
    return this->difficult;
}
 unsigned int Campaign::getNumberPlayers(){
      return this->numberPlayers;
 }
void Campaign::setLevelsInfo(vector<vector<string>> levelsInfo) {
    this->levelsInfo = levelsInfo;
}
